
package ch.hearc.coursJava.kitBase.tableau.equationOrdre2;

import junit.framework.Assert;

public class UseEquationOrdre2LigneCommande
	{

	/*------------------------------------------------------------------*\
	|*							Methodes Public							*|
	\*------------------------------------------------------------------*/

	/**
	 * <pre>
	 * args de type : a=1 b=-3 c=2
	 * Ordre a de l'importance
	 * </pre>
	 */
	public static void main(String[] args)
		{
		Assert.assertTrue(args.length == 3);

		String[] tabA = args[0].split("="); // tabA[0] = "a" tabA[1] = 1
		String[] tabB = args[1].split("="); // tabB[0] = "b" tabB[1] = -3
		String[] tabC = args[2].split("="); // tabC[0] = "c" tabC[1] = 2

		if (isValid(tabA, tabB, tabC))
			{
			double[] tabCoefficients = new double[3];

			try
				{
				tabCoefficients[0] = Double.parseDouble(tabA[1]);
				tabCoefficients[1] = Double.parseDouble(tabB[1]);
				tabCoefficients[2] = Double.parseDouble(tabC[1]);

				if (tabCoefficients[0] == 0 && tabCoefficients[1] == 0)
					{
					System.out.println("Pas de solutions !");
					}
				else
					{
					double[] tabReponse = EquationOrdre2.solve(tabCoefficients);
					EquationOrdre2.afficher(tabReponse);
					}
				}
			catch (NumberFormatException e)
				{
				//e.printStackTrace();
				messageErreur();
				}
			}
		else
			{
			messageErreur();
			}
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Private						*|
	\*------------------------------------------------------------------*/

	private static boolean isValid(String[] tabA, String[] tabB, String[] tabC)
		{
		return tabA.length == 2 && tabB.length == 2 && tabC.length == 2 && tabA[0].equals("a") && tabB[0].equals("b") && tabC[0].equals("c");
		}

	private static void messageErreur()
		{
		System.out.println("Erreur de parametres !");
		System.out.println("Parametres correctes : a=x b=y c=z");
		}
	}
